package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiMonHoc;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiMonHocService;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhi;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiService;

import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVienHocPhitblQLDTTXAHocVienHocPhiMonHocUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private Long id; 
    public void setId(Long id) {
       this.id = id;
 }

    public Long getId() {
       return id;
 }

    
    private TblQLDTTXAHocVienHocPhiService tblQLDTTXAHocVienHocPhiService;
    private TblQLDTTXAMonHocService tblQLDTTXAMonHocService;

    private int hocVienHocPhiId; 
    public int getHocVienHocPhiId() {
       return hocVienHocPhiId;
 }

    public void setHocVienHocPhiId(int hocVienHocPhiId) {
       this.hocVienHocPhiId = hocVienHocPhiId;
 }

    private int monHocId; 
    public int getMonHocId() {
       return monHocId;
 }

    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    private double hocPhiMonHoc; 
    public void setHocPhiMonHoc(double hocPhiMonHoc) {
       this.hocPhiMonHoc = hocPhiMonHoc;
 }

    public double getHocPhiMonHoc() {
       return hocPhiMonHoc;
 }

    private int mienMon; 
    public void setMienMon(int mienMon) {
       this.mienMon = mienMon;
 }

    public int getMienMon() {
       return mienMon;
 }

    private double tienTraLai; 
    public void setTienTraLai(double tienTraLai) {
       this.tienTraLai = tienTraLai;
 }

    public double getTienTraLai() {
       return tienTraLai;
 }

    private int daDongHP; 
    public void setDaDongHP(int daDongHP) {
       this.daDongHP = daDongHP;
 }

    public int getDaDongHP() {
       return daDongHP;
 }

    private double thanhTien; 
    public void setThanhTien(double thanhTien) {
       this.thanhTien = thanhTien;
 }

    public double getThanhTien() {
       return thanhTien;
 }

    private TblQLDTTXAHocVienHocPhiMonHoc tblQLDTTXAHocVienHocPhiMonHoc; 
    public void setTblQLDTTXAHocVienHocPhiMonHoc (TblQLDTTXAHocVienHocPhiMonHoc tblQLDTTXAHocVienHocPhiMonHoc) {
        this.tblQLDTTXAHocVienHocPhiMonHoc = tblQLDTTXAHocVienHocPhiMonHoc;
 }

    private TblQLDTTXAHocVienHocPhiMonHocService tblQLDTTXAHocVienHocPhiMonHocService; 

    private List<TblQLDTTXAHocVienHocPhiMonHoc> tblQLDTTXAHocVienHocPhiMonHocs; 
    public List<TblQLDTTXAHocVienHocPhiMonHoc>  getTblQLDTTXAHocVienHocPhiMonHocs() {
        return tblQLDTTXAHocVienHocPhiMonHocs; 
      } 

	private int preUpdate(Message msg, TblQLDTTXAHocVienHocPhiMonHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAHocVienHocPhiMonHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVienHocPhi_MonHoc", "sua")){ 
        return "noprivilege"; 
    }
        tblQLDTTXAHocVienHocPhiMonHocService = (TblQLDTTXAHocVienHocPhiMonHocService) context.getBean("tbl_QLDTTXA_HocVienHocPhi_MonHocClient"); 
        tblQLDTTXAHocVienHocPhiService = (TblQLDTTXAHocVienHocPhiService) context.getBean("tbl_QLDTTXA_HocVien_HocPhiClient"); 

        tblQLDTTXAMonHocService = (TblQLDTTXAMonHocService) context.getBean("tbl_QLDTTXA_MonHocClient"); 

        msg = new Message(); 
        tblQLDTTXAHocVienHocPhiMonHoc = tblQLDTTXAHocVienHocPhiMonHocService.gettblQLDTTXAHocVienHocPhiMonHoc(new Long(id)); 
        tblQLDTTXAHocVienHocPhiMonHoc.setId(id); 
        tblQLDTTXAHocVienHocPhiMonHoc.setHocPhiMonHoc(hocPhiMonHoc); 
        if(mienMon == 1){ 
           tblQLDTTXAHocVienHocPhiMonHoc.setMienMon(true); 
       } else { 
           tblQLDTTXAHocVienHocPhiMonHoc.setMienMon(false); 
       } 
        tblQLDTTXAHocVienHocPhiMonHoc.setTienTraLai(tienTraLai); 
        if(daDongHP == 1){ 
           tblQLDTTXAHocVienHocPhiMonHoc.setDaDongHP(true); 
       } else { 
           tblQLDTTXAHocVienHocPhiMonHoc.setDaDongHP(false); 
       } 
        tblQLDTTXAHocVienHocPhiMonHoc.setThanhTien(thanhTien); 
        preUpdate(msg,tblQLDTTXAHocVienHocPhiMonHoc); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAHocVienHocPhiMonHocService.updatetblQLDTTXAHocVienHocPhiMonHoc(tblQLDTTXAHocVienHocPhiMonHoc); 
           postUpdate(msg, tblQLDTTXAHocVienHocPhiMonHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

       if(pageSize == 0){ 
           pageSize = 20; 
       } 
        if(page == 0){ 
           page =1; 
       } 
        List < ConditionReport > cons = new ArrayList<ConditionReport>(); 
       ConditionReport con = new ConditionReport(); 
        con.setCol("hocVienHocPhiId.id"); 
        con.setValue1(new Long(hocVienHocPhiId)); 
        con.setOperator("eq"); 
        cons.add(con); 
      tblQLDTTXAHocVienHocPhiMonHocs =       tblQLDTTXAHocVienHocPhiMonHocService.findtblQLDTTXAHocVienHocPhiMonHocByCondition(cons,pageSize, page); 
      pages = tblQLDTTXAHocVienHocPhiMonHocService.counttblQLDTTXAHocVienHocPhiMonHocByCondition(cons)/pageSize + 1; 
      dataString = ""; 
      dataString += "&id="; 
      dataString += "&hocVienHocPhiId="; 
      dataString += "&monHocId="; 
      dataString += "&hocPhiMonHoc="; 
      dataString += "&mienMon="; 
      dataString += "&tienTraLai="; 
      dataString += "&daDongHP="; 
      dataString += "&thanhTien="; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_HocVienHocPhi_MonHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
